package com.travel.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.travel.common.pojo.User;
import com.travel.service.UserService;

@Controller
@RequestMapping("user")
public class UserController {
	
	@Autowired
	private UserService userService;
	
	
	@RequestMapping("/login")
	@ResponseBody
	public Integer login(User user,ModelMap map,HttpSession session) {
		List<User> userList= userService.getUserByUsername(user.getUsername());
		if (0 == userList.size()) {
			session.setAttribute("user", userList.get(0));
			return 1;
		}else if (!user.getPassword().equals(userList.get(0).getPassword())) {
			return 2;
		}else{
			session.setAttribute("user", userList.get(0));
			return 3;
		}
	}

	@RequestMapping("/loginout")
	public String loginout(HttpSession session) {
		System.out.println(1);
		session.invalidate();
		return "redirect:/login.jsp";
	}
	
	


}
